﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class AdminX_Hotel_HotelAdd : System.Web.UI.UserControl
{
    private int nDefaulLang = Support.GetDefaultLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        MessAlert1.HideMessage();
        if (!IsPostBack)
        {
            setLable();
            BindDataToLanguageDropDown();
            BindDataStarRating();
            BindDataToCountryDropdown();
            BindDataPriorityDropdown();
            BindHotelPopular();
            SetValidate();
            InitData();
        }
    }
    private void setLable()
    {
        lblAddress.Text = MultipleLanguage.LBL_ADDRESS[nDefaulLang - 1];
        lblContent.Text = MultipleLanguage.LBL_CONTENT[nDefaulLang - 1];
        lblLanguage.Text = MultipleLanguage.LBL_LANGUAGE[nDefaulLang - 1];
        lblPriceFrom.Text = MultipleLanguage.PRICEFROM[nDefaulLang - 1];
        lblPriceFromTo.Text = MultipleLanguage.PRICEFROMTO[nDefaulLang - 1];
        lblStar.Text = MultipleLanguage.STARRATING[nDefaulLang - 1];
        lblTitle.Text = MultipleLanguage.LBL_TITLE[nDefaulLang - 1];
        lblInitContent.Text = MultipleLanguage.LBL_INIT_CONTENT[nDefaulLang - 1];
        lblGoogleMap.Text = MultipleLanguage.GOOGLEMAP[nDefaulLang - 1];
        lblCountry.Text = MultipleLanguage.LBL_COUNTRY[nDefaulLang - 1];
        lblRegion.Text = MultipleLanguage.LBL_REGION[nDefaulLang - 1];
        lblHotelPopular.Text = MultipleLanguage.HOTEL_POPULAR[nDefaulLang - 1];
        lblDetail.Text = MultipleLanguage.PICTURE_DETAIS[nDefaulLang - 1];
        lblCity.Text = MultipleLanguage.LBL_CITY[nDefaulLang - 1];
        lblPicture1.Text = MultipleLanguage.LBL_IMAGE1[nDefaulLang - 1];
        lblPicture2.Text = MultipleLanguage.LBL_IMAGE2[nDefaulLang - 1];
        lblPicture3.Text = MultipleLanguage.LBL_IMAGE3[nDefaulLang - 1];
        lblPicture4.Text = MultipleLanguage.LBL_IMAGE4[nDefaulLang - 1];
        lblPicture5.Text = MultipleLanguage.LBL_IMAGE5[nDefaulLang - 1];
        lblAvatar.Text = MultipleLanguage.LBL_IMAGE[nDefaulLang - 1];
        btnCancel.Text = MultipleLanguage.BTN_BACK[nDefaulLang - 1];
        btnSave.Text = MultipleLanguage.BTN_SAVE[nDefaulLang - 1];

        chkActive.Text = MultipleLanguage.STATUS_ACTIVE[nDefaulLang - 1];
        chkDisplayOrder.Text = MultipleLanguage.lbl_DesplayOrder[nDefaulLang - 1];

    }
    private void BindDataToLanguageDropDown()
    {
        Languages objLanguage = new Languages();
        DataTable dtbLanguage = new DataTable();
        dtbLanguage = objLanguage.Search();
        ddlLanguage.DataSource = dtbLanguage;
        ddlLanguage.DataValueField = "LanguageID";
        ddlLanguage.DataTextField = "Description";
        ddlLanguage.DataBind();
    }
    private void BindDataToCountryDropdown()
    {
        DataTable dtbCountry = new DataTable();
        Country objCountry = new Country();
        dtbCountry = objCountry.GetALL();

        ddlCountry.DataSource = dtbCountry;
        ddlCountry.DataValueField = "CountryID";
        switch (ConvertData.ConvertToInt(ddlLanguage.SelectedValue))
        {
            case 1:
                ddlCountry.DataTextField = "CountryName1";
                break;
            case 2:
                ddlCountry.DataTextField = "CountryName2";
                break;
            case 3:
                ddlCountry.DataTextField = "CountryName3";
                break;
        }
        ddlCountry.DataBind();
        Utl.SetNonSelectToControl(ddlCountry, MultipleLanguage.DDL_SELECTVALUE[ConvertData.ConvertToInt(ddlLanguage.SelectedValue) - 1], MultipleLanguage.DDL_SELECTVALUE[ConvertData.ConvertToInt(ddlLanguage.SelectedValue) - 1]);
    }
    private void BindDataToRegionDropdown(int nCountry)
    {
        DataTable dtbRegion = new DataTable();
        Region objRegion = new Region();
        dtbRegion = objRegion.SearchByCountry(nCountry);
        ddlRegion.DataSource = dtbRegion;
        ddlRegion.DataValueField = "RegionID";
        switch (ConvertData.ConvertToInt(ddlLanguage.SelectedValue))
        {
            case 1:
                ddlRegion.DataTextField = "RegionName1";
                break;
            case 2:
                ddlRegion.DataTextField = "RegionName2";
                break;
            case 3:
                ddlRegion.DataTextField = "RegionName3";
                break;
        }
        ddlRegion.DataBind();
        Utl.SetNonSelectToControl(ddlRegion, MultipleLanguage.DDL_SELECTVALUE[ConvertData.ConvertToInt(ddlLanguage.SelectedValue) - 1], MultipleLanguage.DDL_SELECTVALUE[ConvertData.ConvertToInt(ddlLanguage.SelectedValue) - 1]);
    }
    private void BindDataToCityDropdown(int nRegion)
    {
        DataTable dtbCity = new DataTable();
        City objCity = new City();
        dtbCity = objCity.SearchByRegion(nRegion);
        ddlCity.DataSource = dtbCity;
        ddlCity.DataValueField = "CityID";
        switch (ConvertData.ConvertToInt(ddlLanguage.SelectedValue))
        {
            case 1:
                ddlCity.DataTextField = "CityName1";
                break;
            case 2:
                ddlCity.DataTextField = "CityName2";
                break;
            case 3:
                ddlCity.DataTextField = "CityName3";
                break;
        }
        ddlCity.DataBind();
        Utl.SetNonSelectToControl(ddlCity, MultipleLanguage.DDL_SELECTVALUE[ConvertData.ConvertToInt(ddlLanguage.SelectedValue) - 1], MultipleLanguage.DDL_SELECTVALUE[ConvertData.ConvertToInt(ddlLanguage.SelectedValue) - 1]);
    }
    private void BindDataStarRating()
    {
        ddlStarRating.Items.Insert(0, new ListItem("---Select---", "0"));
        ddlStarRating.Items.Insert(1, new ListItem("1*", "1"));
        ddlStarRating.Items.Insert(2, new ListItem("2*", "2"));
        ddlStarRating.Items.Insert(3, new ListItem("3*", "3"));
        ddlStarRating.Items.Insert(4, new ListItem("4*", "4"));
        ddlStarRating.Items.Insert(5, new ListItem("5*", "5"));
    }
    private void BindDataPriorityDropdown()
    {
        DataTable dtbHotel = new DataTable();
        Hotel objHotel = new Hotel();
        int nPageCount = 0;
        dtbHotel = objHotel.Search(0, "", 0, 0, 0, 0, 1, 1000, ref nPageCount);
        int nCount = dtbHotel.Rows.Count;
        string sAction = GetQuerryString(Config.ACTION);//Lay Thong tin Edit, Insert
        int nRealValue = 0;
        if (sAction == Config.ACTION_EDIT)//Kiem tra dieu kien
        {
            eHotel eHotelEntity = this.HotelEntity();
            if (ConvertData.ConvertToInt(eHotelEntity.Priority) < nCount)
            {
                nRealValue = nCount;
            }
            else
            {
                nRealValue = ConvertData.ConvertToInt(eHotelEntity.Priority);
            }
            for (int i = 0; i < nRealValue; i++)
            {
                ddlPriority.Items.Add(ConvertData.ConvertToString(i + 1));
            }

            string sPriority = ConvertData.ConvertToString(eHotelEntity.Priority);
            ddlPriority.SelectedValue = sPriority;
        }
        else
        {
            nRealValue = nCount + 1;
            for (int i = 0; i < nRealValue; i++)
            {
                ddlPriority.Items.Add(ConvertData.ConvertToString(i + 1));
            }
            ddlPriority.SelectedValue = ConvertData.ConvertToString(nRealValue);
        }
    }
    private void SetValidate()
    {
        rfvTitle.ErrorMessage = MessagesValidate.HOTEL_EMPTY[nDefaulLang - 1];
        rfvInitContent.ErrorMessage = MessagesValidate.INITCONTENT_EMPTY[nDefaulLang - 1];
        revPriceFrom.ErrorMessage = MessagesValidate.PRICEFROM_NUMBER[nDefaulLang - 1];
        revPriceFromTo.ErrorMessage = MessagesValidate.PRICEFROMTO_NUMBER[nDefaulLang - 1];
    }
    private void InitData()
    {
        string sQueery = ConvertData.ConvertToString(Request.QueryString[Config.ACTION]);
        try
        {
            if (sQueery == Config.ACTION_EDIT)
            {
                int nItemID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
                GetDataToHotelPopularDesc(nItemID);
                if (nItemID > 0)
                {
                    tblGallery.Visible = true;
                    GetData(nItemID);
                }
            }
            else
            {
                BindDataToRegionDropdown(0);
                BindDataToCityDropdown(0);
                tblGallery.Visible = false;
                imgImage.ImageUrl = Config.IMAGE_NO_IMAGE;
            }
        }
        catch
        {
            string sRedirect = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_HOTEL + "&" + Config.MESS_ID + "=" + Config.ITEM_NOTEXIST;
            Response.Redirect(sRedirect);
        }
    }
    private void GetData(int ItemID)
    {
        // Get data to view on UI Controls
        int nDisplayOrder = 0;
        int nStatus = 0;
        int nLangID = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        Hotel objHotel = new Hotel();
        objHotel.LoadById(ItemID);

        City objCity = new City();
        objCity.LoadById(objHotel.Data.CityID);
        Region objRegion = new Region();
        objRegion.LoadById(objCity.Data.RegionID);

        BindDataToCityDropdown(objCity.Data.RegionID);
        BindDataToRegionDropdown(objRegion.Data.CountryID);
        ddlCity.SelectedValue = ConvertData.ConvertToString(objHotel.Data.CityID);
        ddlRegion.SelectedValue = ConvertData.ConvertToString(objCity.Data.RegionID);
        ddlCountry.SelectedValue = ConvertData.ConvertToString(objRegion.Data.CountryID);

        ddlStarRating.SelectedValue = ConvertData.ConvertToString(objHotel.Data.StarRating);
        txtGoogleMap.Text = ConvertData.ConvertToString(objHotel.Data.GoogleMapAddress);
        FTBVideoLink.IntialText(ConvertData.ConvertToString(objHotel.Data.VideoLink));
        switch (nLangID)
        {
            case 1:
                txtTitle.Text = objHotel.Data.Title1;
                txtInitContent.Text = ConvertData.ConvertToString(objHotel.Data.InitContent1);
                FTBContent.IntialText(ConvertData.ConvertToString(objHotel.Data.Content1));

                txtAddress.Text = ConvertData.ConvertToString(objHotel.Data.Address1);
                txtPriceFrom.Text = ConvertData.ConvertToString(objHotel.Data.PriceFrom1);
                txtPriceFromTo.Text = ConvertData.ConvertToString(objHotel.Data.PriceFromTo1);
                break;
            case 2:
                txtTitle.Text = objHotel.Data.Title2;
                txtInitContent.Text = ConvertData.ConvertToString(objHotel.Data.InitContent2);
                FTBContent.IntialText(ConvertData.ConvertToString(objHotel.Data.Content2));

                txtAddress.Text = ConvertData.ConvertToString(objHotel.Data.Address2);
                txtPriceFrom.Text = ConvertData.ConvertToString(objHotel.Data.PriceFrom2);
                txtPriceFromTo.Text = ConvertData.ConvertToString(objHotel.Data.PriceFromTo2);
                
                break;
            case 3:
                txtTitle.Text = objHotel.Data.Title3;
                txtInitContent.Text = ConvertData.ConvertToString(objHotel.Data.InitContent3);
                FTBContent.IntialText(ConvertData.ConvertToString(objHotel.Data.Content3));

                txtAddress.Text = ConvertData.ConvertToString(objHotel.Data.Address3);
                txtPriceFrom.Text = ConvertData.ConvertToString(objHotel.Data.PriceFrom3);
                txtPriceFromTo.Text = ConvertData.ConvertToString(objHotel.Data.PriceFromTo3);
                break;
        }

        string sImage = objHotel.Data.Image;
        if (sImage.Length > 0)
            imgImage.ImageUrl = Config.ROOT + Config.IMAGE_HOTEL_DEFAULT_UPLOAD + sImage;
        else imgImage.ImageUrl = Config.IMAGE_NO_IMAGE;
        int nPageCount = 0;
        DataTable dtbHotel = new DataTable();
        HotelImages objImage = new HotelImages();
        dtbHotel = objImage.Search(ItemID, 1, 10000, ref nPageCount);
        dtlGallery.DataSource = dtbHotel;
        dtlGallery.DataBind();

        nDisplayOrder = ConvertData.ConvertToInt(objHotel.Data.Priority);
        if (nDisplayOrder > 0)
            chkDisplayOrder.Checked = true;
        else
            chkDisplayOrder.Checked = false;
        
        nStatus = ConvertData.ConvertToInt(objHotel.Data.Status);
        if (nStatus > 0)
            chkActive.Checked = true;
        else
            chkActive.Checked = false;

    }
    private string GetQuerryString(string sQuerry)
    {
        string sQuerryString = "";
        sQuerryString = ConvertData.ConvertToString(Request.QueryString[sQuerry]);
        return sQuerryString;
    }
    private void UpdateImage(int nItemID)
    {
        string sFile1 = "";
        string sFile2 = "";
        string sFile3 = "";
        string sFile4 = "";
        string sFile5 = "";
        Session[Config.SESSION_GALLERYID] = ConvertData.ConvertToString(nItemID);
        if (iptFile1.Value != string.Empty) sFile1 = Support.UploadFile(iptFile1, "hotel");
        if (iptFile2.Value != string.Empty) sFile2 = Support.UploadFile(iptFile2, "hotel");
        if (iptFile3.Value != string.Empty) sFile3 = Support.UploadFile(iptFile3, "hotel");
        if (iptFile4.Value != string.Empty) sFile4 = Support.UploadFile(iptFile4, "hotel");
        if (iptFile5.Value != string.Empty) sFile5 = Support.UploadFile(iptFile5, "hotel");

        HotelImages objImage = new HotelImages();
        objImage.Data.HotelID = nItemID;
        int nResult = 0;

        if (sFile1 != "")
        {
            objImage.Data.FileName = sFile1;
            nResult = objImage.Insert();
        }
        if (sFile2 != "")
        {
            objImage.Data.FileName = sFile2;
            nResult = objImage.Insert();
        }
        if (sFile3 != "")
        {
            objImage.Data.FileName = sFile3;
            nResult = objImage.Insert();
        }
        if (sFile4 != "")
        {
            objImage.Data.FileName = sFile4;
            nResult = objImage.Insert();
        }
        if (sFile5 != "")
        {
            objImage.Data.FileName = sFile5;
            nResult = objImage.Insert();
        }
        GetData(nItemID);

        Session[Config.SESSION_GALLERYID] = "0";
    }
    private eHotel HotelEntity()
    {
        eHotel entityHotel = new eHotel();
        int nItemID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
        string sQueery = ConvertData.ConvertToString(Request.QueryString[Config.ACTION]);
        if (nItemID > 0 && sQueery == Config.ACTION_EDIT)
        {
            Hotel objHotel = new Hotel();
            objHotel.LoadById(nItemID);
            entityHotel = objHotel.Data;
        }
        return entityHotel;
    }
    private eHotel SetData()
    {
        string sQueery = ConvertData.ConvertToString(Request.QueryString[Config.ACTION]);
        int nLangID = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
        eHotel eHotelEntity = this.HotelEntity();
        Hotel objHotel = new Hotel();

        objHotel.Data.Image = eHotelEntity.Image;

        string sContent = ConvertData.ConvertToString(FTBContent.RenderText());
        string sInitContent = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtInitContent.Text.Trim()));
        string sGoogleMap = ConvertData.ConvertToString(txtGoogleMap.Text.Trim());
        string title = ConvertData.ConvertToString(txtTitle.Text);
        string sAddress = txtAddress.Text;
        double sPriceForm = ConvertData.ConvertToDouble(ConvertData.RemoveHTMLTag(txtPriceFrom.Text.Trim()));
        double sPriceFromTo = ConvertData.ConvertToDouble(ConvertData.RemoveHTMLTag(txtPriceFromTo.Text.Trim()));
        objHotel.Data.StarRating = ConvertData.ConvertToInt(ddlStarRating.SelectedValue);
        objHotel.Data.GoogleMapAddress = sGoogleMap;
        objHotel.Data.CityID = ConvertData.ConvertToInt(ddlRegion.SelectedValue);
        string sMainContent = ConvertData.ConvertToString(FTBVideoLink.RenderText());
        objHotel.Data.VideoLink = sMainContent;
        switch (nLangID)
        {
            case 1:
                objHotel.Data.Title1 = title;
                objHotel.Data.Content1 = sContent;
                objHotel.Data.InitContent1 = sInitContent;
                
                objHotel.Data.Address1 = sAddress;
                objHotel.Data.PriceFrom1 = sPriceForm;
                objHotel.Data.PriceFromTo1 = sPriceFromTo;

                objHotel.Data.Address2 = eHotelEntity.Address2;
                objHotel.Data.PriceFrom2 = eHotelEntity.PriceFrom2;
                objHotel.Data.PriceFromTo2 = eHotelEntity.PriceFromTo2;
                objHotel.Data.Address3 = eHotelEntity.Address3;
                objHotel.Data.PriceFrom3 = eHotelEntity.PriceFrom3;
                objHotel.Data.PriceFromTo3 = eHotelEntity.PriceFromTo3;

                objHotel.Data.InitContent2 = eHotelEntity.InitContent2;
                objHotel.Data.InitContent3 = eHotelEntity.InitContent3;
                objHotel.Data.Content2 = eHotelEntity.Content2;
                objHotel.Data.Content3 = eHotelEntity.Content3;
                objHotel.Data.Title2 = eHotelEntity.Title2;
                objHotel.Data.Title3 = eHotelEntity.Title3;

                break;
            case 2:
                objHotel.Data.Title2 = title;
                objHotel.Data.Content2 = sContent;
                objHotel.Data.InitContent2 = sInitContent;

                objHotel.Data.Address2 = sAddress;
                objHotel.Data.PriceFrom2 = sPriceForm;
                objHotel.Data.PriceFromTo2 = sPriceFromTo;

                objHotel.Data.Address1 = eHotelEntity.Address1;
                objHotel.Data.PriceFrom1 = eHotelEntity.PriceFrom1;
                objHotel.Data.PriceFromTo1 = eHotelEntity.PriceFromTo1;
                objHotel.Data.Address3 = eHotelEntity.Address3;
                objHotel.Data.PriceFrom3 = eHotelEntity.PriceFrom3;
                objHotel.Data.PriceFromTo3 = eHotelEntity.PriceFromTo3;

                objHotel.Data.InitContent1 = eHotelEntity.InitContent1;
                objHotel.Data.InitContent3 = eHotelEntity.InitContent3;
                objHotel.Data.Content1 = eHotelEntity.Content1;
                objHotel.Data.Content3 = eHotelEntity.Content3;
                objHotel.Data.Title1 = eHotelEntity.Title1;
                objHotel.Data.Title3 = eHotelEntity.Title3;
                break;
            case 3:
                objHotel.Data.Title3 = title;
                objHotel.Data.Content3 = sContent;
                objHotel.Data.InitContent3 = sInitContent;

                objHotel.Data.Address3 = sAddress;
                objHotel.Data.PriceFrom3 = sPriceForm;
                objHotel.Data.PriceFromTo3 = sPriceFromTo;

                objHotel.Data.Address1 = eHotelEntity.Address1;
                objHotel.Data.PriceFrom1 = eHotelEntity.PriceFrom1;
                objHotel.Data.PriceFromTo1 = eHotelEntity.PriceFromTo1;
                objHotel.Data.Address2 = eHotelEntity.Address2;
                objHotel.Data.PriceFrom2 = eHotelEntity.PriceFrom2;
                objHotel.Data.PriceFromTo2 = eHotelEntity.PriceFromTo2;

                objHotel.Data.InitContent2 = eHotelEntity.InitContent2;
                objHotel.Data.InitContent1 = eHotelEntity.InitContent1;
                objHotel.Data.Content2 = eHotelEntity.Content2;
                objHotel.Data.Content1 = eHotelEntity.Content1;
                objHotel.Data.Title2 = eHotelEntity.Title2;
                objHotel.Data.Title1 = eHotelEntity.Title1;
                break;
        }
        string sImage = "";
        if (iptImage.Value != "")
        {
            Support.DeleteFile("hotel", eHotelEntity.Image);
            sImage = Support.UploadFile(iptImage, "hotel");
        }
        else
        {
            if (sQueery == Config.ACTION_EDIT)
                sImage = eHotelEntity.Image;
        }
        objHotel.Data.Image = sImage;
        if (chkDisplayOrder.Checked) objHotel.Data.Priority = ConvertData.ConvertToInt(ddlPriority.SelectedValue);
        else objHotel.Data.Priority = 0;

        if (chkActive.Checked) objHotel.Data.Status = Config.STATUS_ACTIVE;
        else objHotel.Data.Status = Config.STATUS_INACTIVE;

        
        return objHotel.Data;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage() - 1;
        int nCityID = ConvertData.ConvertToInt(ddlCity.SelectedValue);
        if (nCityID > 0)
        {
            int nActionResult = 0;
            int nDefaulLang = Support.GetDefaultLanguage() - 1;
            Hotel objHotel = new Hotel();
            objHotel.Data = SetData();
            string sAction = GetQuerryString(Config.ACTION);
            if (sAction == Config.ACTION_EDIT)
            {
                int nItemID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
                nActionResult = objHotel.Update(nItemID);
                int n = SetDataToHotelPopular(nActionResult);
                if (n > 0)
                {
                    if (nActionResult * n > 0)
                    {
                        UpdateImage(nItemID);
                        MessAlert1.ShowMessage(1, MessagesAlert.UPDATE_SUCCESSFUL[nDefaulLang]);
                        if (objHotel.Data.Image.ToString() != "") imgImage.ImageUrl = Config.ROOT + Config.IMAGE_HOTEL_DEFAULT_UPLOAD + objHotel.Data.Image.ToString();
                    }
                }
                else
                    MessAlert1.ShowMessage(2, MessagesAlert.UPDATE_UNSUCCESSFUL[nDefaulLang]);
            }
            else
            {
                nActionResult = objHotel.Insert();
                if (nActionResult > 0)
                {
                    int n = SetDataToHotelPopular(nActionResult);
                    if (n > 0)
                    {

                        UpdateImage(nActionResult);
                        string sURL = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_HOTEL + "&" + Config.MESS_ID + "=" + Config.MESSAGE_INSERT;
                        Response.Redirect(sURL);
                    }
                }

            }
        }
        else
        {
            MessAlert1.ShowMessage(2, MessagesValidate.REGION_SELECT[nDefaultLanguage]);
        }
    }
    protected void dtlGallery_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        int nDefaulLang = Support.GetDefaultLanguage();
        int nItemID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Image imgImage = (Image)e.Item.FindControl("imgImage");
            LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");
            imgImage.ImageUrl = Config.ROOT + Config.IMAGE_HOTEL_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "FileName"));

            lnkDelete.Text = MultipleLanguage.BTN_DELETE[nDefaulLang - 1];

            lnkDelete.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "HotelImages"));
            lnkDelete.OnClientClick = Support.CreateConfirmBoxClient(MessagesAlert.DELETE_ALERT[nDefaulLang]);
        }
    }
    protected void dtlGallery_ItemCommand(object source, DataListCommandEventArgs e)
    {
        int nItemID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);
        HotelImages objHotelImages = new HotelImages();
        switch (strCommand)
        {
            case "Delete":
                objHotelImages.LoadById(nID);
                Support.DeleteFile("hotel", objHotelImages.Data.FileName);

                int nDelete = objHotelImages.DeleteById(nID);
                GetData(nItemID);
                break;
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        string sRedirect = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_HOTEL;
        Response.Redirect(sRedirect);
    }
    protected void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e)
    {
        InitData();
    }
    protected void rptHotelPopular_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            CheckBox chkHotelPopular = (CheckBox)e.Item.FindControl("chkHotelPopular");
            Label lblHotelPopularID = (Label)e.Item.FindControl("lblHotelPopularID");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "HotelPopularID"));
            lblHotelPopularID.Text = ConvertData.ConvertToString(nID);
            int nCurrentLang = ConvertData.ConvertToInt(ddlLanguage.SelectedValue);
            switch (nCurrentLang)
            {
                case 1:
                    chkHotelPopular.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1"));
                    break;
                case 2:
                    chkHotelPopular.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2"));
                    break;
                case 3:
                    chkHotelPopular.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3"));
                    break;
            }
        }
    }
    private void GetDataToHotelPopularDesc(int HotelID)
    {
        HotelPopularDescription objHotelTrans = new HotelPopularDescription();
        DataTable dtbTrans = objHotelTrans.SearchByHotelID(HotelID);
        int nCount = rptHotelPopular.Items.Count;
        foreach (DataRow row in dtbTrans.Rows)
        {
            for (int i = 1; i <= nCount; i++)
            {
                CheckBox chk = (CheckBox)rptHotelPopular.Items[i - 1].FindControl("chkHotelPopular");
                Label lblID = (Label)rptHotelPopular.Items[i - 1].FindControl("lblHotelPopularID");

                string sID = ConvertData.ConvertToString(row["HotelPopularID"]);
                if (sID == lblID.Text)
                {
                    chk.Checked = true;
                }
            }
        }
    }
    private int SetDataToHotelPopular(int HotelID)
    {
        HotelPopularDescription dtgHotelPopularsDesc = new HotelPopularDescription();
        int nresult = 0;
        nresult = dtgHotelPopularsDesc.DeleteByHotelID(HotelID);
        if (nresult == 0)
        {
            return 0;
        }

        int nCount = rptHotelPopular.Items.Count;
        for (int i = 1; i <= nCount; i++)
        {
            CheckBox chk = (CheckBox)rptHotelPopular.Items[i - 1].FindControl("chkHotelPopular");
            Label lblID = (Label)rptHotelPopular.Items[i - 1].FindControl("lblHotelPopularID");
            int nID = ConvertData.ConvertToInt(lblID.Text);
            if (chk.Checked)
            {
                HotelPopularDescription dtgHotelPopularsDescport = new HotelPopularDescription();
                dtgHotelPopularsDescport.Data.HotelID = HotelID;
                dtgHotelPopularsDescport.Data.HotelPopularID = nID;
                nresult = dtgHotelPopularsDescport.Insert();
                if (nresult == 0)
                {
                    return 0;
                }
            }
        }
        return nresult;
    }
    private void BindHotelPopular()
    {
        HotelPopular objPopular = new HotelPopular();
        DataTable dtbPopular = new DataTable();
        dtbPopular = objPopular.GetAll();
        rptHotelPopular.DataSource = dtbPopular;
        rptHotelPopular.DataBind();
    }
    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        int nCountry = ConvertData.ConvertToInt(ddlCountry.SelectedValue);
        BindDataToRegionDropdown(nCountry);
        int nRegion = ConvertData.ConvertToInt(ddlCity.SelectedValue);
        BindDataToCityDropdown(nRegion);
    }
    protected void ddlRegion_SelectedIndexChanged(object sender, EventArgs e)
    {
        int nRegion = ConvertData.ConvertToInt(ddlRegion.SelectedValue);
        BindDataToCityDropdown(nRegion);
    }
}